package com.biqee.service.bq.impl;

import java.util.List;

import com.biqee.dao.BqEstimateResultDAO;
import com.biqee.model.db.BqEstimateResult;
import com.biqee.model.db.BqEstimateResultQueryView;
import com.biqee.service.bq.BqEstimateResultService;

public class BqEstimateResultServiceImpl implements BqEstimateResultService {

	@Override
	public Integer create(BqEstimateResult bqEstimateResult) {
		BqEstimateResult estimateResultInDb = readBySiteItem(bqEstimateResult.getBqTuanId(), bqEstimateResult.getSite(), bqEstimateResult.getSiteItemId());
		if(estimateResultInDb == null) {
			return bqEstimateResultDAO.create(bqEstimateResult);
		} else {
			return estimateResultInDb.getId();
		}
	}
	
	@Override
	public BqEstimateResult readBySiteItem(Integer bqTuanId, String site, String siteItemId) {
		return bqEstimateResultDAO.read(bqTuanId, site, siteItemId);
	}

	@Override
	public void updateScoreById(int score, Integer id) {
		bqEstimateResultDAO.updateScoreById(score, id);
	}

	@Override
	public List<BqEstimateResultQueryView> readMoreThanList(int score,
			int start, int number, int bqTuanId) {
		return bqEstimateResultDAO.readMoreThanList(score, start, number, bqTuanId);
	}

	@Override
	public List<BqEstimateResultQueryView> readLessThanList(int score,
			int start, int number, int bqTuanId) {
		return bqEstimateResultDAO.readLessThanList(score, start, number, bqTuanId);
	}

	@Override
	public List<BqEstimateResultQueryView> readBetweenList(int lowScore,
			int highScore, int start, int number, int bqTuanId) {
		return bqEstimateResultDAO.readBetweenList(lowScore, highScore, start, number, bqTuanId);
	}

	@Override
	public void deleteByBqTuanId(Integer bqTuanId) {
		bqEstimateResultDAO.deleteByBqTuanId(bqTuanId);
	}
	
	@Override
	public List<BqEstimateResult> readBqEstimateResultsByBqTuanId(
			Integer bqTuanId) {
		return bqEstimateResultDAO.readBqEstimateResultsByBqTuanId(bqTuanId);
	}


	private BqEstimateResultDAO bqEstimateResultDAO;

	public void setBqEstimateResultDAO(BqEstimateResultDAO bqEstimateResultDAO) {
		this.bqEstimateResultDAO = bqEstimateResultDAO;
	}

	
}
